
function checkCode(){
    let code = $("#code").val();
    let email = $("#email").val();
    let state = false;
    if (code != "" && email != "") {
        $.ajax({
            //请求方式
            type : "post",
            //请求的媒体类型
            // contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "/user/code",
            //数据，json字符串
            data: "code=" + code,
            dataType:"json",
            async: false,
            //请求成功
            success : function(result) {
                if (result.code == "0"){
                    state = true;
                } else {
                    showNotification("top","提示","验证码错误！","danger")
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                showNotification("top","提示","发送失败！","danger")
            }
        });
    }
    return state;
}
$(function () {
    let email;
    $("#sendCodeBtn").bind("click" , function () {
        let time = 60;
        email = $("#email").val();
        $("#sendCodeBtn").attr("disabled","disabled");
        let timer = setInterval(function () {
            $("#sendCodeBtn").text(time);
            if (time === 0){
                $("#sendCodeBtn").attr("disabled",null);
                $("#sendCodeBtn").text("发送");
                clearInterval(timer)
            }
            time-- ;
        },1000);
        $.ajax({
            //请求方式
            type : "get",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "/user/code",
            //数据，json字符串
            data : {"accountEmail":email},
            dataType:"json",
            //请求成功
            success : function(result) {
                showNotification("top","提示","发送成功！","info")
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                showNotification("top","提示","发送失败！","danger")
            }
        });
    });
    $("#email").bind("blur",function () {
        email = $(this).val();
        $.ajax({
            //请求方式
            type : "get",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url : "/user/email",
            //数据，json字符串
            data : {"accountEmail":email},
            dataType:"json",
            //请求成功
            success : function(result) {
                if (!result.data.available) {
                    showNotification("top","提示",email + "已被注册！","danger");
                    $("#email").val(null)
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                showNotification("top","提示","请求失败！","danger")
            }
        });
    })
});

